home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Embed / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.6 KB  |  302 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef COMMAND_H
  27. #include "Command.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. #ifndef SELECT_H
  35. #include "Select.h"
  36. #endif
  37.  
  38. #ifndef DEFINES_K
  39. #include "Defines.k"
  40. #endif
  41.  
  42. // ----- Framework Includes -----
  43.  
  44. #ifndef FWUTIL_H
  45. #include "FWUtil.h"
  46. #endif
  47.  
  48. #ifndef FWCONTXT_H
  49. #include "FWContxt.h"
  50. #endif
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWPXYFRM_H
  57. #include "FWPxyFrm.h"
  58. #endif
  59.  
  60. #ifndef FWGROWBX_H
  61. #include "FWGrowBx.h"
  62. #endif
  63.  
  64. #ifndef FWSCLBAR_H
  65. #include "FWSclBar.h"
  66. #endif
  67.  
  68. #ifndef FWFCTCLP_H
  69. #include "FWFctClp.h"
  70. #endif
  71.  
  72. // ----- OS Layer Includes -----
  73.  
  74. #ifndef FWODGEOM_H
  75. #include "FWODGeom.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. #ifndef FWMNUBAR_H
  83. #include "FWMnuBar.h"
  84. #endif
  85.  
  86. // ----- OpenDoc Includes -----
  87.  
  88. #ifndef SOM_Module_OpenDoc_Commands_defined
  89. #include <CmdDefs.xh>
  90. #endif
  91.  
  92. #ifndef SOM_Module_OpenDoc_StdProps_defined
  93. #include <StdProps.xh>
  94. #endif
  95.  
  96. //========================================================================================
  97. //    Runtime information
  98. //========================================================================================
  99.  
  100. #ifdef FW_BUILD_MAC
  101. #pragma segment odfembed
  102. #endif
  103.  
  104. FW_DEFINE_AUTO(CEmbedFrame)
  105.  
  106. //========================================================================================
  107. //    CLASS CEmbedFrame
  108. //========================================================================================
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //     CEmbedFrame::CEmbedFrame
  112. //----------------------------------------------------------------------------------------
  113.  
  114. CEmbedFrame::CEmbedFrame(Environment* ev, 
  115.                         ODFrame* odFrame, 
  116.                         FW_CPresentation* presentation, 
  117.                         CEmbedPart* part,
  118.                         CEmbedContent* content) :
  119.     FW_CEmbeddingFrame(ev, odFrame, presentation, part),
  120.     FW_MDraggableFrame(ev, this),
  121.     FW_MDroppableFrame(ev, this),
  122.     fPart(part),
  123.     fContent(content)
  124. {
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //     CEmbedFrame::~CEmbedFrame
  129. //----------------------------------------------------------------------------------------
  130.  
  131. CEmbedFrame::~CEmbedFrame()
  132. {
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //     CEmbedFrame::Draw
  137. //----------------------------------------------------------------------------------------
  138.  
  139. void CEmbedFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  140. {
  141.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  142.  
  143.     FW_CRectShape::RenderRect(vc, GetBounds(ev), FW_kFill, FW_kRGBBlue);
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //     CEmbedFrame::Draw
  148. //----------------------------------------------------------------------------------------
  149.  
  150. void CEmbedFrame::CreateSubViews(Environment* ev)
  151. {        
  152.     // ----- Create a GrowBox only in root frame
  153.     //         Note:     You do not need CreateSubViews if the views are defined in resources.
  154.     //                See the Container or Form samples
  155.     
  156.     if (this->IsRoot(ev)) 
  157.     {
  158.         FW_CRect frameRect = GetBounds(ev);  
  159.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  160.         frameRect.right -= sbSize.x;
  161.         frameRect.bottom -= sbSize.y;
  162.         
  163.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  164.     }
  165.  
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    CEmbedFrame::CanAcceptDrop
  170. //----------------------------------------------------------------------------------------
  171. // As an embedding frame I can accept anything
  172.  
  173. ODDragResult CEmbedFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  174. {
  175. FW_UNUSED(ev);
  176. FW_UNUSED(dragInfo);
  177.     return TRUE;
  178. }
  179.  
  180. //---------------------------------------------------------------------------------------
  181. //    CEmbedFrame::DoAdjustMenus
  182. //---------------------------------------------------------------------------------------
  183.  
  184. FW_Handled CEmbedFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  185. {
  186. FW_UNUSED(isRoot);
  187.     if (hasMenuFocus)
  188.     {
  189.         // Check clipboard for a part to paste
  190.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
  191.     
  192.         // If an embedded part is selected, change Copy menu item to "Copy Part"
  193.         if (GetPresentation(ev)->GetSelection(ev)->IsEmpty(ev))
  194.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy"));
  195.         else
  196.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy Part"));
  197.     }
  198.     
  199.     return FW_kNotHandled;
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CEmbedFrame::CreateFrameShape
  204. //----------------------------------------------------------------------------------------
  205. //    Returns a new shape equals to my frame shape inset by eight pixels. Otherwise I can't drop 
  206. //    anything
  207.  
  208. ODShape* CEmbedFrame::CreateFrameShape(Environment* ev)
  209. {
  210.     FW_CRect bounds = GetBounds(ev);
  211.     bounds.Inset(kBorder);
  212.     bounds.Place(FW_kFixed0, FW_kFixed0);        // Frame shape always zero based
  213.     return ::FW_NewODShape(ev, bounds);
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    CEmbedFrame::FrameShapeChanged
  218. //----------------------------------------------------------------------------------------
  219. //    Change the frame shape of the embedded frame to be the same as mine minus a border
  220.  
  221. void CEmbedFrame::FrameShapeChanged(Environment* ev)
  222. {
  223.     // Must call inherited so our "view" superclass gets adjusted.
  224.     FW_CEmbeddingFrame::FrameShapeChanged (ev);
  225.     
  226.     CEmbedProxy* proxy = fContent->GetProxy();
  227.     if (proxy != NULL)
  228.     {
  229.         FW_CAcquiredODFrame embeddedFrame = proxy->AcquireEmbeddedFrame(ev, this);
  230.         
  231.         FW_CAcquiredODShape frameShape = CreateFrameShape(ev);
  232.         embeddedFrame->ChangeFrameShape(ev, frameShape, NULL);
  233.     }
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    CEmbedFrame::NewClipboardCommand
  238. //----------------------------------------------------------------------------------------
  239.  
  240. FW_CClipboardCommand* CEmbedFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  241. {
  242.     FW_Boolean undoAble = TRUE;
  243.     if (commandID == kODCommandPasteAs)
  244.         undoAble = FALSE;
  245.  
  246.     return FW_NEW(CEmbedEditCommand, (ev, 
  247.                                         commandID,
  248.                                         fContent,
  249.                                         this,
  250.                                         GetPresentation(ev)->GetSelection(ev),
  251.                                         undoAble));
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    CEmbedFrame::NewDropCommand
  256. //----------------------------------------------------------------------------------------
  257.  
  258. FW_CDropCommand* CEmbedFrame::NewDropCommand(Environment* ev,
  259.                                              FW_CFrame* frame,
  260.                                              ODDragItemIterator* dropInfo, 
  261.                                              ODFacet* odFacet, 
  262.                                              const FW_CPoint& dropPoint)
  263. {
  264. FW_UNUSED(frame);
  265.     return FW_NEW(CEmbedDropCommand, (ev, fContent, this, dropInfo, odFacet, dropPoint));
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    CEmbedFrame::NewDragCommand
  270. //----------------------------------------------------------------------------------------
  271.  
  272. FW_CDragCommand* CEmbedFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
  273. {
  274. FW_UNUSED(theFrame);
  275. FW_UNUSED(theMouseEvent);
  276.     
  277.     return FW_NEW(CEmbedDragCommand, (ev, fContent, this, (CEmbedSelection*)GetPresentation(ev)->GetSelection(ev)));
  278. }
  279.  
  280. //----------------------------------------------------------------------------------------
  281. //    CEmbedFrame::NewInsertCommand
  282. //----------------------------------------------------------------------------------------
  283. FW_CInsertCommand* CEmbedFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  284. {
  285.     return FW_NEW(CEmbedInsertCommand, (ev,
  286.                                         this,
  287.                                         fileSpec,
  288.                                         fContent));
  289. }
  290.  
  291. //----------------------------------------------------------------------------------------
  292. // CEmbedFrame::DoMouseDownInEmbeddedFrameBorder
  293. //----------------------------------------------------------------------------------------
  294.  
  295. FW_Handled CEmbedFrame::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  296. {    
  297.     Drag(ev, theBorderMouseEvent);
  298.     
  299.     return FW_kHandled;
  300. }
  301.  
  302.